/*
 * @Author: Binhuang4
 * @Date: 2019-06-03 16:07:24
 * @LastEditors: Binhuang4
 * @LastEditTime: 2019-06-04 17:04:37
 * @Description: file content
 */

package main

import "fmt"

func main() {
	fmt.Println(twoSum([]int{2, 7, 11, 15}, 26))
	fmt.Println(twoSum1([]int{2, 7, 11, 15}, 26))
}

func twoSum(nums []int, target int) []int {
	count := len(nums)
	for i := 0; i < count; i++ {
		for j := i + 1; j < count; j++ {
			if nums[i]+nums[j] == target {
				return []int{i, j}
			}
		}
	}
	return []int{}
}

func twoSum1(nums []int, target int) []int {
	count := len(nums)
	var tmpMap = make(map[int]int)
	for i := 0; i < count; i++ {
		minus := target - nums[i]
		if j, ok := tmpMap[minus]; ok {
			return []int{i, j}
		}
		tmpMap[nums[i]] = i
	}
	return []int{}
}
